package game;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;

public class GraphicUtil
{
    public static void clearScreen(Graphics2D g, int width, int height, Position maxXY)
    {
        if (width > maxXY.getWidth())
        {
            width = maxXY.getWidth();
        }
        if (height > maxXY.getHeight())
        {
            height = maxXY.getHeight();
        }
        Color color = g.getColor();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, width, height);
        g.setColor(color);
    }
    
    public static void renderCenterText(Graphics g, String s, int fontSize, Position maxXY)
    {
        g.setFont(new Font("Monospaced", Font.PLAIN, fontSize));
        FontMetrics fm = g.getFontMetrics();
        int startX = maxXY.getWidth() / 2 - fm.stringWidth(s) / 2;
        int startY = maxXY.getHeight() / 2 + fm.getDescent();
        int offset = 5;
        int width = offset + fm.stringWidth(s) + offset;
        int height = offset + fm.getHeight();
        g.setColor(Color.BLUE);
        g.fillRect(startX - offset, startY - (offset * 3), width, height);
        g.setColor(Color.WHITE);
        g.drawString(s, startX, startY);
    }
}
